﻿using System;
using System.Data;
using System.Data.OleDb;

namespace YArchitech.HVAC
{
	public class DataAccess
	{
		public static DataSet GetDataSet(string sqlStr, string tableName)
		{
			OleDbConnection oleDbConnection = new OleDbConnection(DataAccess.strCon);
			DataSet dataSet = new DataSet();
			oleDbConnection.Open();
			new OleDbDataAdapter(sqlStr, oleDbConnection).Fill(dataSet, tableName);
			oleDbConnection.Close();
			return dataSet;
		}

		public static int ExecuteSQL(string sqlStr)
		{
			int result;
			using (OleDbConnection oleDbConnection = new OleDbConnection(DataAccess.strCon))
			{
				OleDbCommand oleDbCommand = new OleDbCommand();
				oleDbCommand.Connection = oleDbConnection;
				oleDbCommand.CommandText = sqlStr;
				oleDbConnection.Open();
				oleDbCommand.ExecuteNonQuery();
				oleDbConnection.Close();
				result = 1;
			}
			return result;
		}

		private static string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + WinFormTools.hyDataPath() + "LoadParam.mdb;Persist Security Info=True;";
	}
}
